<?php
namespace app\dsadmin\controller;
use think\Db;
use think\Cache;
class Zhifu extends Base
{
    public function index()
    {
        if (input("post."))
        {
            $content = serialize(input("post."));
            Db::name("zhifu")->where(['id' => 1])->update(['content' => $content]);
            
        // if(Cache::store('redis')->has('weixinpay')){
        //     $zhifu = Db::name("zhifu")->where('id', 1)->find();
        //     Cache::store('redis')->set('weixinpay',json_encode($zhifu));
        // }

            return ['code' => 1, 'msg' => "修改成功！"];
        }
        
      
       
        
        

        $zhifu = Db::name("zhifu")->where('id', 1)->find();

        $content = unserialize($zhifu['content']);

        $this->assign("content", $content);

        return $this->fetch();
    }
    
    public function jingyong(){
        $type = input('type');
        $time = time() - 1600;
        $list = Db::name('ip')->where(['shijian' => ['gt',$time],'zftd' => 1])->select();
        foreach ($list as $v){
            $info = Db::name('uopenid')->where(['uopenid' => $v['uopenid']])->find();
            if(!$info){
                $insert['uopenid'] = $v['uopenid'];
                $insert['zftd']    = $v['zftd'];
                $insert['userid']  = $v['userid'];
                $insert['ddh']     = $v['ddh'];
                $insert['time']    = date('Y-m-d H:i:s', time());
                $insert['ip']      = $v['ip'];
                Db::name('uopenid')->insert($insert);
            }
           
        }
        return ['code' => 1, 'msg' => "禁用成功！"];
    
    }
    
    public function index_specific()
    {
       
        $id = input('id', 1);
        $tabs = array(1 => '巅峰支付', 2 => '国际支付', 3 => '冈本支付', 4 => '冈本金蝶支付',5 => '618支付', 6 => '蘑菇支付',7 => '麻雀支付',8 => 'gogo支付',9 => '鸡sir支付',10 => '鸡sir支付宝');
        
        $zhifu = Db::name("zhifu")->where('id', $id)->find();
        
       
        $content = unserialize($zhifu['content']);
        
        // var_dump($content);
        // die;
        $this->assign("tabs", $tabs);
		$this->assign("content", $content);
        $this->assign('id', $id);
        return $this->fetch();
    }
    
    public function save($id)
    {
        if (input("post."))
        {
            $content = serialize(input("post."));
            $update = Db::name("zhifu")->where(['id' => $id])->update(['content' => $content]);
            if(empty($update)){
                $insert = Db::name("zhifu")->insert(['id'=>$id,'content'=>$content]);
                if($insert){
                    return ['code' => 1, 'msg' => "修改成功！"];
                }
            }else {
                // code...
                return ['code' => 1, 'msg' => "修改成功！"];
            }
        }
    }
}
